/**
 * There are <a href="https://github.com/thinkgem/jeesite">JeeSite</a> code generation
 */
package com.boxin.ims.modules.wechat.service;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.BaseService;
import com.boxin.ims.modules.wechat.entity.BusinessConfig;
import com.boxin.ims.modules.wechat.dao.BusinessConfigDao;

/**
 * 微信特殊服务配置类Service
 * @author Jakemanse
 * @version 2013-09-27
 */
@Component
@Transactional(readOnly = true)
public class BusinessConfigService extends BaseService {

	@SuppressWarnings("unused")
	private static Logger logger = LoggerFactory.getLogger(BusinessConfigService.class);
	
	@Autowired
	private BusinessConfigDao businessConfigDao;
	
	public BusinessConfig get(Long id) {
		return businessConfigDao.findOne(id);
	}
	
	
	public List<BusinessConfig> findAll(){
		DetachedCriteria dc = businessConfigDao.createDetachedCriteria();
		dc.add(Restrictions.eq("delFlag", BusinessConfig.DEL_FLAG_NORMAL));
		dc.addOrder(Order.desc("id"));
		
		return businessConfigDao.find(dc);
	}
	
	public Page<BusinessConfig> find(Page<BusinessConfig> page, BusinessConfig businessConfig) {
		DetachedCriteria dc = businessConfigDao.createDetachedCriteria();
		if (StringUtils.isNotEmpty(businessConfig.getName())){
			dc.add(Restrictions.like("name", "%"+businessConfig.getName()+"%"));
		}
		if (StringUtils.isNotEmpty(businessConfig.getRemarks())){
			dc.add(Restrictions.like("remarks", "%"+businessConfig.getRemarks()+"%"));
		}
		dc.add(Restrictions.eq("delFlag", BusinessConfig.DEL_FLAG_NORMAL));
		dc.addOrder(Order.desc("id"));
		return businessConfigDao.find(page, dc);
	}
	
	@Transactional(readOnly = false)
	public void save(BusinessConfig businessConfig) {
		businessConfigDao.save(businessConfig);
	}
	
	@Transactional(readOnly = false)
	public void delete(Long id) {
		businessConfigDao.deleteById(id);
	}
	
}
